// 店铺

import type { GeneratePredetermineDatesAndTimeRangesNeedInfo } from '@/components/predetermine-datetime-selector/utils.type'
import type R from '@/types/conduit/R'
import type GeoCoordinates from '@/types/generic/GeoCoordinates'
import type { SearchNearbyShopsPage } from '@/types/param/shop'
import {
  NearbyShop,
  NearbyShopProduct,
  type ShopInfo,
  type ShopPreferentialLabelInfoVO,
  type ShopToUserDeliveryInfo
} from '@/types/response/shop'
import request from '@/utils/request'
import type { Page } from '@/types/generic/Page'
import type { PageResponse } from '@/types/generic/PageResponse'

export const searchNearbyShops = (searchNearbyShops: SearchNearbyShopsPage): Promise<R<PageResponse<NearbyShop>>> =>
  request({
    url: `/shop/shop/search-nearby-shops`,
    method: 'GET',
    params: searchNearbyShops
  })
export const searchNearbyShopProducts = (
  searchNearbyShops: SearchNearbyShopsPage
): Promise<R<PageResponse<NearbyShopProduct>>> =>
  request({
    url: `/shop/shop/search-nearby-shop-products`,
    method: 'GET',
    params: searchNearbyShops
  })

export const getShopInfoById = (shopId: number | string): Promise<R<ShopInfo>> =>
  request({
    url: `/shop/shop/${shopId}`,
    method: 'GET'
  })
export const shopPredetermineInfo = (shopId: number): Promise<R<GeneratePredetermineDatesAndTimeRangesNeedInfo>> =>
  request({
    url: `/shop/shop/shop-predetermine-info`,
    method: 'GET',
    params: { shopId }
  })
export const shopDeliveryInfoByUserLocation = (
  shopId: number | string,
  geoCoordinates: GeoCoordinates
): Promise<R<ShopToUserDeliveryInfo>> =>
  request({
    url: `/shop/shop/shop-delivery-info-by-user-location`,
    method: 'GET',
    params: { shopId, ...geoCoordinates }
  })
/**
 * 查询可用于店铺优惠的优惠信息（活动与券）
 */
export const getApplicableShopPreferential = (shopId: number | string): Promise<R<ShopPreferentialLabelInfoVO>> =>
  request({
    url: `/shop/shop/applicable-shop-preferential/${shopId}`,
    method: 'GET'
  })
/**
 * 邀请朋友一起点餐
 */
export const inviteFriends = (shopId: number | string): Promise<R<string>> =>
  request({
    url: `/shop/shop/invite`,
    method: 'POST',
    params: { shopId }
  })

/**
 * 查询当前是否是多人点餐中
 */
export const getMyOrderingInvitationCode = (shopId: number | string): Promise<R<string>> =>
  request({
    url: `/shop/shop/invite`,
    method: 'GET',
    params: { shopId }
  })

/**
 * 结束多人点餐
 */
export const offMulti = (shopId: number | string): Promise<R<void>> =>
  request({
    url: `/shop/shop/invite`,
    method: 'DELETE',
    params: { shopId }
  })
